<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use Input;
use DB;
use App\Admin\Lists;

class ListsController extends Controller
{
    //显示单据列表
    public function index() {
    	
    	$data = Lists::where('isdel','2')->get();
    	
    	return view('admin.lists.index',compact('data'));
    	
    }
    
    //添加单据
    public function add(){
    	
    	//判断请求类型
        if(Input::method() == 'POST'){
            //处理
            $data = Input::except('uploadfile','file-2','_token','file');
           
            //写入数据
            $result = Lists::insert($data);
            //转化bool类型
            return $result ? '1' : '0';
        }else{
         
            //展示视图
            return view('admin.lists.add');
        }
    }
    
    
    //编辑
    public function edit(){

        if(Input::method() == 'POST'){

            $id = Input::get('id');
            // dd($id);

            $data = Input::except('uploadfile','file-2','_token','file');

            // $data = {'password' => bcrypt($pwd)}s;
			
			
            $result = Lists::where('id','=',$id) -> update($data);

            return $result ? '1' : '0';
            

        } else {

            $id = Input::get('id');
            $data = Lists::where('id','=',$id) -> get();
            
            //显示待修改的表单
            return view('admin.lists.edit',compact('data'));

        }

    }



    
    //软删除
    public function del(){
        // $res = Auth::guard('admin') -> user();
        // dd($res);

        // dd(Input::get('id'));

        $id = Input::get('id');

        $result = Lists::where('id','=',$id) -> update(['isdel' => '1']);

       return $result ? '1' : '0';
        
    }
    
    
    
}
